#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "form1.h"
#include "form2.h"

#include "widgetmanager.h"
#include <QPushButton>
#include <QDebug>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    form1 = new Form1();

    WidgetManager::getWidgetManager()->addWidget("form1",form1);

    form2 = new Form2();

    WidgetManager::getWidgetManager()->addWidget("form2",form2);

    //MainWindow 窗口已经创建好了窗口实例，这里不需要自己创建
    WidgetManager::getWidgetManager()->addWidget("mainWin",this);

    connect(ui->form1,&QPushButton::clicked,[=]{
        if(WidgetManager::getWidgetManager()->getWidget("form1")==nullptr){
            qDebug()<<"指针为空";
        }else {
            WidgetManager::getWidgetManager()->getWidget("form1")->show();
        }
    });

    connect(ui->form2,&QPushButton::clicked,[=]{
         WidgetManager::getWidgetManager()->getWidget("form2")->show();
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}
